package com.ble.lightscreen;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SettingActivity extends AppCompatActivity {
    private EditText oe1,oe3,oe4;
    private Button submit2;
    private String scantime;
    private String url = null;
    private String pname = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        oe1 = findViewById(R.id.scantime);
        oe3 = findViewById(R.id.tourl);
        oe4 = findViewById(R.id.toapp);
        submit2 = findViewById(R.id.submit2);

        submit2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Conf con = new Conf();
                //从编辑框获取内容写入到配置文件
                if (!oe1.getText().toString().equals("")) {
                    scantime = oe1.getText().toString();
                    con.writeDateToLocalFile("scantime", scantime);
                }
                if (!oe3.getText().toString().equals("")) {
                    url = oe3.getText().toString();
                    con.writeDateToLocalFile("url", url);
                }
                if (!oe4.getText().toString().equals("")) {
                    pname = oe4.getText().toString();
                    con.writeDateToLocalFile("pname", pname);
                }
                Toast.makeText(SettingActivity.this,"设置成功",Toast.LENGTH_LONG).show();
                        Intent intent = new Intent(SettingActivity.this,BleLightService.class);
                        startService(intent);
            }
        });
    }
}
